package com.qfedu.aunt.commons.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qfedu.aunt.commons.pojo.Orders;
import com.qfedu.aunt.commons.result.R;
import com.qfedu.aunt.commons.service.OrdersService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 订单表 前端控制器
 * </p>
 *
 * @author xiaobobo
 * @since 2022-10-26
 */
@RestController
@RequestMapping("/aunt/commons/orders")
@Api(description = "订单模块",tags = "订单模块")
public class OrdersController {

    @Autowired
    private OrdersService ordersService;

    /**
     * 他通过订单类型和城市名字获取订单
     * @param cityName
     * @param orderType
     * @param currentPage
     * @param pageSize
     * @return
     */
    @ApiOperation("通过订单类型和城市名字分页查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "cityName",value = "城市名字",dataType = "string",paramType = "path",required = true),
            @ApiImplicitParam(name = "orderType",value = "订单类型",dataType = "string",paramType = "path",required = true),
            @ApiImplicitParam(name = "currentPage",value = "当前页码",dataType = "int",paramType = "path",required = true),
            @ApiImplicitParam(name = "pageSize",value = "数据条目数",dataType = "int",paramType = "path",required = true),
            @ApiImplicitParam(name = "token",value = "用户身份标识",dataType = "string",paramType = "header",required = true)
    })
    @GetMapping("/findOrdersByCityNameAndType/{cityName}/{orderType}/{currentPage}/{pageSize}")
    public R findOrdersByCityNameAndType(
            @PathVariable("cityName") String cityName,
            @PathVariable("orderType") String orderType,
            @PathVariable("currentPage") Integer currentPage,
            @PathVariable("pageSize") Integer pageSize) throws Exception {
        IPage<Orders> ordersIPage=ordersService.findOrdersByCityNameAndType(cityName,orderType,currentPage,pageSize);
        return R.ok().setData("orderList",ordersIPage.getRecords()).setData(
                "total",ordersIPage.getTotal()
        );
    }

    /**
     * 通过城市名字 获取最新的订单信息
     * @param cityName
     * @param currentPage
     * @param pageSize
     * @return
     */
    @ApiOperation("通过城市名字获取最新的这个订单信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "cityName",value = "城市名字",dataType = "string",paramType = "path",required = true),
            @ApiImplicitParam(name = "currentPage",value = "当前页码",dataType = "int",paramType = "path",required = true),
            @ApiImplicitParam(name = "pageSize",value = "数据条目数",dataType = "int",paramType = "path",required = true),
            @ApiImplicitParam(name = "token",value = "用户身份标识",dataType = "string",paramType = "header",required = true)
    })
    @GetMapping("/findOrdersByCityName/{cityName}/{currentPage}/{pageSize}")
    public R findOrdersByCityName(@PathVariable("cityName") String cityName,@PathVariable("currentPage") Integer currentPage,@PathVariable("pageSize") Integer pageSize){
       IPage<Orders> ordersIPage= ordersService.findOrdersByCityName(cityName,currentPage,pageSize);
       return R.ok().setData("orderList",ordersIPage.getRecords()).setData("total",ordersIPage.getTotal());
    }




}

